﻿
@{
    ViewBag.Title = "订单查询";
    Layout = "~/Views/Shared/_LayoutEasyUI.cshtml";
}

<table id="grid-list"> </table>

<div id="toolbar" style="display:none;">
    <div style="margin: 10px 0 5px 20px; height: 35px;">
        <select id="slStatus" class="easyui-combobox" style="width:200px;" data-options="editable:false,panelHeight:'auto'">
            <option value="-1">全部</option>
            <option value="0">已审核</option>
            <option value="1">已分配</option>
            <option value="2">已确认</option>
            <option value="3">已发货</option>
            <option value="4">已签收</option>
        </select>
        <input id="ss" class="easyui-searchbox" style="width: 300px"
               data-options="searcher:qq,prompt:'请输入查询信息',menu:'#mm'" />

        <div id="mm" style="width:120px">
            <div data-options="name:'FOrderNo'">订单编号</div>
            <div data-options="name:'FShrName'">姓名</div>
        </div>

    </div>
</div>

@section scripts{

    <script>
        function qq(value, name) {
            //todo:查询
            var status = $('#slStatus').combobox('getValue');
            Grid.list.datagrid('load', { status: status, key: name, value: value });
        }

        var supplierGrid = {
            GetChecked: function () {
            }
        };
        $(function () {
            Grid.LoadData();
            var name = $('#ss').searchbox('getName');
            var value = $('#ss').searchbox('getValue');
            $('#slStatus').combobox({
                onChange: function (n, o) {
                    Grid.list.datagrid('load', { status: n, key: name, value: value });
                }
            });
        });

        var Grid = {
            LoadData: function () {
                var url = "/Order/ManagerData";
                Grid.list = $("#grid-list").datagrid({
                    url: url,
                    title: '订单物流预选',
                    fit: true,
                    fitColumns: true,
                    pagination: true,
                    singleSelect: false,
                    rownumbers: true,
                    nowrap: false,
                    striped: true, //隔行变色
                    toolbar: '#toolbar',
                    columns: [[
                        { field: 'ck', checkbox: true, align: 'left', width: 50 },
                        {
                            field: 'Status', title: '订单状态', width: 80, align: 'center', formatter: function (value, row, index) {
                                switch (value) {
                                    case 0:
                                        return "已审核";
                                    case 1:
                                        return "已分配";
                                    case 2:
                                        return "已确认";
                                    case 3:
                                        return "已发货";
                                    case 4:
                                        return "已签收";
                                    default:
                                        return "--";
                                }
                            }
                        },
                        { field: 'FOrderNo', title: '订单编号', width: 150, align: 'center' },
                        { field: 'FStoreName', title: '门店', width: 100, align: 'center' },
                        { field: 'FVipName', title: '会员名称', width: 80, align: 'center' },
                        { field: 'FShrName', title: '姓名', width: 80, align: 'center' },
                        { field: 'FShrTel', title: '电话', width: 120, align: 'center' },
                        { field: 'FAddress', title: '联系地址', width: 100, align: 'center' },
                        { field: 'FIndex', title: '行号', width: 40, align: 'center' },
                        { field: 'FItemName', title: '产品名称', width: 100, align: 'center' },
                         { field: 'FGgModel', title: '产品型号', width: 100, align: 'center' },
                         { field: 'FQty', title: '数量', width: 50, align: 'center' },
                         { field: 'FWeight', title: '重量', width: 50, align: 'center' },
                         { field: 'FVolume', title: '体积', width: 80, align: 'center' },
                         { field: 'FBjPrice', title: '保价金额', width: 80, align: 'center' },
                        { field: 'FDt', title: '有无电梯', width: 50, align: 'center' },
                        { field: 'FTranspBillNo', title: '运单号', width: 100, align: 'center' },
                        {
                            field: 'TranspPrice1', title: '报价(入户)', width: 100, align: 'center', formatter: function (value, row, index) {
                                return value === 0 ? '' : value;
                            }
                        },
                        {
                            field: 'TranspPrice2', title: '报价(不入户)', width: 100, align: 'center', formatter: function (value, row, index) {
                                return value === 0 ? '' : value;
                            }
                        }
                    ]],
                    onLoadSuccess: onLoadSuccess
                });
            },
            Refresh: function () {
                Grid.list.datagrid('reload');
            }
        }

        function onLoadSuccess(data) {
            var _orderid;
            var _index = -1;
            var _rowspan = 0;
            for (var i = 0; i < data.rows.length; i++) {
                if (_orderid != data.rows[i].FOrderId) {
                    //合并；
                    if (_rowspan > 1) {
                        mergeCell(_index, _rowspan);
                    }
                    _orderid = data.rows[i].FOrderId;
                    _index = i;
                    _rowspan = 1;
                } else {
                    _rowspan = _rowspan + 1;
                }
            }
            if (_rowspan > 1) {
                mergeCell(_index, _rowspan);
            }
        }

        function mergerCell(_index, _rowspan) {
            $(Grid.list).datagrid('mergeCells', {
                index: _index,
                field: 'ck',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'Status',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FOrderNo',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FStoreName',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FVipName',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FShrName',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FShrTel',
                rowspan: _rowspan
            }).datagrid('mergeCells', {
                index: _index,
                field: 'FAddress',
                rowspan: _rowspan
            });
        }
    </script>
}